<?php
	include ('../Utilities/connect.php');
	function getAllUser()
	{
		$sql= "select * from user";
		$rl=mysql_query($sql, getConnect());
		$arr=array();
		while ($user = mysql_fetch_array($rl))
		{
		 	$arr[]=$user;
		}
		return $arr;	
	}
	
	function getAllRole()
	{
		$sql= "select * from role";
		$rl=mysql_query($sql, getConnect());
		$arr=array();
		while ($user = mysql_fetch_array($rl))
		{
		 	$arr[]=$user;
		}
		return $arr;
	}
	function checkUser($name,$pass)
	{
		$sql="select UserID, UserName, Password,Email, Role from user, role where UserName='$name' and Password='$pass' and user.RoleID=role.RoleId";
		$rl=mysql_query($sql, getConnect());
		return $rl;
	}
	function checkUsername($username)
	{
	 	$sql= "select * from  user where UserName= '".$username."'";
		@$rl=mysql_query($sql, getConnect());
		if(mysql_num_rows($rl)!= 0)
		{
		 	return true;
		}
		return false;
	}
	function checkEmail($email)
	{
	 	$sql= "select * from  user where Email= '".$email."'";
		$rl=mysql_query($sql, getConnect());
		if(mysql_num_rows($rl)!=0)
		{
		 	return true;
		}
		return false;
	}
	function insertUser ($name, $pass, $email)
	{
		$sql= "insert into user(UserName,Password,Email, RoleID) values ('".$name."', '".$pass."', '".$email."', 3)";
		$rl=mysql_query($sql, getConnect());
		if($rl)
		{
		return 1;
		}
		else return 0;
	}
	function updateUser($id,$name,$pass,$email,$roleid)
	{
		$sql= "update user set UserName='$name', Password='$pass' , Email='$email', RoleID='$roleid' where UserID='$id'";
		$rl=mysql_query($sql, getConnect());
		if($rl)
		{
		return 1;
		}
		else return 0;
	}
	function deleteUser($id)
	{
	   $sql= "delete from user where UserID='$id'";
		$rl=mysql_query($sql, getConnect());
		if($rl)
		{
			return 1;
		}
		else return 0;
	}
	function changepass($id,$pass)
	{
		$sql= "update user set  Password='$pass' where UserID='$id'";
		$rl=mysql_query($sql, getConnect());
		if($rl)
		{
		return 1;
		}
		else return 0;
	  
	}
	

?>